home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / dynaweb.idb / usr / lib / Insight / data / config / urlutil.dwc.z / urlutil.dwc
Encoding:
Text File  |  1997-07-30  |  7.1 KB  |  168 lines

  1. ##===========================================================================
  2. ##   URL construction utilities.
  3. ##===========================================================================
  4.  
  5. #############################################################################
  6. #############################################################################
  7. ##                                                                         ##
  8. ##  Mostly by convention, the DynaWeb URL looks something like:            ##
  9. ##                                                                         ##
  10. ##     http://www.ebt.com/<service>/<path>;<url_params>?<query_params>     ##
  11. ##                                                                         ##
  12. ##  where <service> is usually "dynaweb" and where <path> consists of:     ##
  13. ##                                                                         ##
  14. ##     <root_path>/@<script_name>/<selection>                              ##
  15. ##                                                                         ##
  16. ##  and where <root_path> consists of:                                     ##
  17. ##                                                                         ##
  18. ##     <collection_name>/<collection_name>/.../<book_name>                 ##
  19. ##                                                                         ##
  20. ##  Note that <script> may refer to either a dwScript or a dwTemplate,     ##
  21. ##  and <selection> semantics are script-dependent.                        ##
  22. ##                                                                         ##
  23. ##  Example:                                                               ##
  24. ##                                                                         ##
  25. ##  http://www.ebt.com/dynaweb/Manuals/Admin_guide/@BookTocView/446        ##
  26. ##                       |        |           |           |       |        ##
  27. ##         Service-------+        |           |           |       |        ##
  28. ##                   Collection---+           |           |       |        ##
  29. ##                                Book--------+           |       |        ##
  30. ##                                      Viewing template--+       |        ##
  31. ##                                                   Target node--+        ##
  32. ##                                                                         ##
  33. #############################################################################
  34. #############################################################################
  35.  
  36. ##==============================================================================
  37. ## Build URL fragments that are suitable for constructing 
  38. ## different kinds of URLs.  The following parts are made:
  39. ##
  40. ##   BaseUrl - A fully qualified URL including the root path
  41. ##             (note: ends with a '/').  Suitable for use as a <BASE> HREF.
  42. ##             Example: http://www.foo.com/dynaweb/collection/book/
  43. ##
  44. ##   BasePath - Like the BaseUrl, but does not include the
  45. ##             scheme, host, or port, and does not end with '/'.
  46. ##             Suitable for use as a relative Url.
  47. ##             Example: /dynaweb/collection/book
  48. ##
  49. ##   RootAbsUrlPath - Like BasePath, but does not include the
  50. ##             URL prefix or service.
  51. ##             Example: /collection/book
  52. ##
  53. ##   UrlQueryString - If a query is active this will be a string
  54. ##             representing the query preceded by a '?' that is
  55. ##             suitable for tacking on the end of URLs
  56. ##             Example: ?DwebQuery=this+is+a+search+string
  57. ##
  58. ##   UrlParamString - This is a string that is suitable for
  59. ##             inserting in the URL between the path and the
  60. ##             query string. It contains state variables for
  61. ##             the current "session".
  62. ##             Example: ;td=3;hf=1
  63. ##
  64. ##   Careful: If RootPath is empty, avoid sending back a trailing slash.
  65. ##=============================================================================
  66.  
  67. dwScript dwMakeUrlParts {
  68.     set root      [dwGetRootPath]
  69.     set service   [dwGetUrlNthPathSeg 0]
  70.     set prefix    [dwGetUrlPrefix]
  71.     set script    [dwGetUrlNthPathSeg [expr [dwGetUrlNumPathSegs] - 1]]
  72.  
  73.     if {$prefix == "/"} {set prefix ""}
  74.     
  75.     ## Build BasePath, RootAbsUrlPath, and BaseUrl
  76.     
  77.     dwSet BasePath $prefix/$service
  78.     dwSet Service $service
  79.     
  80.     if {$root == ""} {
  81.         dwSet RootAbsUrlPath $prefix/$service
  82.     } else {
  83.         dwSet RootAbsUrlPath $prefix/$service/$root
  84.     }
  85.     
  86.     set port [dwGetUrlPort]
  87.     if {$port == "80"} {
  88.          dwSet dwPort :$port
  89.     } else {
  90.          set dwPort ""
  91.     }
  92.  
  93.     dwSet BaseUrl \
  94.           "[dwGetUrlScheme]://[dwGetUrlServer]:[dwGetUrlPort]$RootAbsUrlPath/"
  95.  
  96.     ##=======================================================================
  97.     ## Build a URL-encoded version of the the query parameter
  98.     ## so we can tack it on URLs we create.
  99.     ## [TODO: built-in function "dwGetEncodedUrlQueryParam"]
  100.     ##=======================================================================
  101.  
  102.    if {[dwGet ActiveQuery] != ""} {
  103.       dwSet UrlQueryString "?DwebQuery=[dwUrlEncode [dwGetUrlQueryParam DwebQuery]]"
  104.    } else {
  105.       dwSet UrlQueryString ""
  106.    }
  107.    
  108.     ##=======================================================================
  109.     ## Turn the current state into a semicolon-separated list of
  110.     ## key=value parameters.
  111.     ##=======================================================================
  112.     
  113.     dwSet UrlParamString ""
  114.     if {[dwGet State__CollTocDepth] != [dwGetParam Default__CollTocDepth]} {
  115.         dwSet UrlParamString \
  116.           "$UrlParamString;cd=[dwUrlEncode [dwGet State__CollTocDepth]]"
  117.     }
  118.     if {[dwGet State__TocDepth] != [dwGetParam Default__TocDepth]} {
  119.         dwSet UrlParamString \
  120.           "$UrlParamString;td=[dwUrlEncode [dwGet State__TocDepth]]"
  121.     }
  122.     if {[dwGet State__Frames] != [dwGet State__FramesSupport]} {
  123.         dwSet UrlParamString \
  124.           "$UrlParamString;hf=[dwUrlEncode [dwGet State__Frames]]"
  125.     }
  126.     if {[dwGet State__Tables] != [dwGetParam Default__TablesFlag]} {
  127.         dwSet UrlParamString \
  128.           "$UrlParamString;ht=[dwUrlEncode [dwGet State__Tables]]"
  129.     }
  130.     if {[dwGet State__Entities] != [dwGetParam Default__EntitiesFlag]} {
  131.         dwSet UrlParamString \
  132.           "$UrlParamString;he=[dwUrlEncode [dwGet State__Entities]]"
  133.     }
  134.     if {[dwGet State__NoNavigation] != 0} {
  135.         dwSet UrlParamString  "$UrlParamString;nn=1"
  136.     }
  137.     if {[dwGet ActiveQuery] != ""} {
  138.        if {[dwGet State__NoAutoHit] != 0} {
  139.            dwSet UrlParamString  "$UrlParamString;nh=1"
  140.        }
  141.     }
  142.  
  143.    set cs_state [dwGet State__ContentStyle]
  144.    if {$cs_state != "" && $cs_state != "default"} {
  145.         dwSet UrlParamString \
  146.           "$UrlParamString;cs=[dwUrlEncode $cs_state]"
  147.    }
  148.    set ts_state [dwGet State__TocStyle]
  149.    if {$ts_state != "" && $ts_state != "default"} {
  150.         dwSet UrlParamString \
  151.           "$UrlParamString;ts=[dwUrlEncode $ts_state]"
  152.    }
  153.  
  154.    
  155.     ## Suppress the return value, else it goes to the client and
  156.     ## messes up the output stream.
  157.  
  158.     dwReturn
  159. }
  160.  
  161.  
  162. ## Here's an example of how to remove a URL param from the URL.
  163.  
  164. dwScript RemoveHfUrlParam {
  165.         regsub {;hf=[0-9]+} "[dwGet UrlParamString]" {} UrlParamString
  166.         dwReturn
  167. }
  168.